/*-----------------------------------------------------------------------------
 * @file   hal_gpio.h
 * @brief  interface for GPIO module operations
 * @author WLH<wanglehui8357@163.com> Copyright (C) 2021~2099.
 ----------------------------------------------------------------------------*/
#ifndef HAL_GPIO_H
#define HAL_GPIO_H

#include "globaldef.h"

BEGIN_DECLS

/*-----------------------------------------------------------------------------
 * Predefine GPIO Pins ID number
-----------------------------------------------------------------------------*/
#define HAL_GPIO_PIN_0    (0x00u)
#define HAL_GPIO_PIN_1    (0x01u)
#define HAL_GPIO_PIN_2    (0x02u)
#define HAL_GPIO_PIN_3    (0x03u)
#define HAL_GPIO_PIN_4    (0x04u)
#define HAL_GPIO_PIN_5    (0x05u)
#define HAL_GPIO_PIN_6    (0x06u)
#define HAL_GPIO_PIN_7    (0x07u)
#define HAL_GPIO_PIN_NULL (0xFFu)

/*-----------------------------------------------------------------------------
 * Call back functions type when EXTI interrupt occurred, invoke in ISR
-----------------------------------------------------------------------------*/
typedef void (*EXTI_HANDLER)(U8 pin);

typedef enum
{
    EXTI_LOW_LEVEL,
    EXTI_HIGH_LEVEL,
    EXTI_FALL_EDGE,
    EXTI_RISE_EDGE,
    EXTI_BOTH_EDGE,
} EXTI_TYPE;

/*-----------------------------------------------------------------------------
 * public functions
-----------------------------------------------------------------------------*/
/**
 * @brief init MCU internal GPIO controller
 */
void hal_gpio_init(void);
/**
 * @brief set GPIO out to Hight Level
 * @param pin Predefine GPIO Pins ID number
 */
void hal_gpio_set(U8 pin);
/**
 * @brief set GPIO out to Low Level
 * @param pin Predefine GPIO Pins ID number
 */
void hal_gpio_reset(U8 pin);
/**
 * @brief toggle GPIO out state
 * @param pin Predefine GPIO Pins ID number
 */
void hal_gpio_toggle(U8 pin);
/**
 * @brief get GPIO out state
 * @param pin Predefine GPIO Pins ID number
 */
U8 hal_gpio_read(U8 pin);
/**
 * @brief get GPIO out channel count
 * @param pin Predefine GPIO Pins ID number
 */
U8 hal_gpio_out_count(void);
/**
 * @brief get GPIO in channel count
 * @param pin Predefine GPIO Pins ID number
 */
U8 hal_gpio_in_count(void);
/**
 * @brief initialize GPIO controller for EXTI
 * @param cb Callback function for IO interrupt
 * @param pin Predefine GPIO Pins ID number
 * @param it_type IO Interrupt trigger type
 */
void hal_gpio_exti_init(EXTI_HANDLER cb, U8 pin, EXTI_TYPE it_type);

END_DECLS

#endif //~HAL_GPIO_H
